<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页</title>
    <link rel="stylesheet" type="text/css" th:href="@{../static/css/nav.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{../static/css/index.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{../static/css/index3.css}" />
</head>
<body>
        <div class="nav">
            <div><a id="index" th:href="@{/toIndex}">收支查询</a></div>
            <div><a id="index2" th:href="@{/toIndex2}">财务明细</a></div>
            <div><a id="index3" th:href="@{/toIndex3}">成员管理</a></div>
            <div id="nav"></div>
            <div><a id="login" th:href="${session.name==null}?'/login/toLogin':'/login/toHomepage'"><p id="logState">登录</p></a></div>
        </div>
		<h1>成员管理</h1>
        <table class="memberManager">
            <thead>
                <tr class="head">
                    <th hidden></th>
                    <th>昵称</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>备注</th>
                    <th>权限</th>
                    <th class="short">修改</th>
                    <th class="short">删除</th>
                </tr>
            </thead>
            <tbody>
                <tr class="body" th:each="u:${lowUser}">
                    <form method="post" th:id="${u.getUserid()}">
                        <td hidden><input th:value="${u.getUserid()}" name="userid" ></td>
                        <td><input th:value="${u.getName()}" name="name" required></td>
                        <td><input th:value="${u.getUsername()}" name="username" required></td>
                        <td><input th:value="${u.getPassword()}" name="password" required></td>
                        <td><input th:value="${u.getRemarks()}" name="remarks" required></td>
                        <td><input th:value="${u.getAuthority()}" name="authority" th:id="'auth'+${u.getUserid()}" required class="auth"></td>
                        <td><input type="button" value="修改" id="btn-mo" th:onclick="'javascript:moclick('+${u.getUserid()}+')'"></td>
                        <td><input type="button" value="删除" id="btn-de" th:onclick="'javascript:declick('+${u.getUserid()}+')'"></td>
                    </form>
                </tr>
            </tbody>
        </table>

<script th:inline="javascript">
    window.onload = function() {
        var name = [[${session.name}]];
        console.log(name)
        if (name!=null && name!=""){
            document.getElementById("logState").innerText = name;
        }
        var authmsg = [[${authmsg}]];
        if (authmsg!=null) alert(authmsg);
    }
    function moclick(uid){
        var f = document.getElementById(uid);
        var authid = "auth"+uid;
        var auth = document.getElementById(authid).value;
        if (auth==="0" || auth==="1" || auth==="2"){
            f.action = "/update/user";
            f.submit();
        }else alert("权限格式有误！");
    }
    function declick(uid){
        var f2 = document.getElementById(uid);
        f2.action = "/delete/user";
        f2.submit();
    }
</script>
</body>
</html>
